﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAO;
using BUS;

namespace GUI
{
    public partial class frmMain : DevComponents.DotNetBar.Office2007RibbonForm
    {
        public frmMain()
        {
            InitializeComponent();
        }

        public NHANVIEN nhanvien = new NHANVIEN();

        private void frmMain_Load(object sender, EventArgs e)
        {
            switch (nhanvien.LoaiNV)
            {
                case 1: //quản lý
                    btnThemMonAn.Enabled = true;
                    btnCapNhatMonAn.Enabled = true;
                    btnLapTheKH.Enabled = true;
                    btnThemHDVe.Enabled = true;
                    btnThemHDBar.Enabled = true;
                    btnThongKe.Enabled = true;
                    btnPCBep.Enabled = true;
                    btnPCPV.Enabled = true;
                    break;
                case 2: //bếp trưởng
                    btnThemMonAn.Enabled = true;
                    btnCapNhatMonAn.Enabled = true;
                    btnThongKe.Enabled = true;
                    break;
                case 3: //thu ngân
                    btnLapTheKH.Enabled = true;
                    btnThemHDVe.Enabled = true;
                    btnThemHDBar.Enabled = true;
                    btnThongKe.Enabled = true;
                    break;
                case 4: //thu mua
                    btnThongKe.Enabled = true;
                    break;
                case 5: //kho
                    btnThongKe.Enabled = true;
                    break;
                default:
                    break;
            }
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void btnThemHDBar_Click(object sender, EventArgs e)
        {
            frmHoaDonBar frm = new frmHoaDonBar(this);
            frm.nv = nhanvien;
            TabCreating(tabControlMain, "Hóa đơn Bar", frm);
        }

        private void btnThemHDVe_Click(object sender, EventArgs e)
        {
            frmHoaDonVe frm = new frmHoaDonVe(this);
            frm.nv = nhanvien;
            TabCreating(tabControlMain, "Hóa đơn Vé", frm);
        }



        private void btnThemMonAn_Click(object sender, EventArgs e)
        {
            frmThemMonAn frm = new frmThemMonAn(this);
            frm.nv = nhanvien;
            TabCreating(tabControlMain, "Thêm món ăn", frm);
        }

        private void btnCapNhatMonAn_Click(object sender, EventArgs e)
        {
            frmCapNhatMonAn frm = new frmCapNhatMonAn(this);
            frm.nv = nhanvien;

            TabCreating(tabControlMain, "Cập nhật món ăn", frm);
        }

        private void btnDangXuat_Click(object sender, EventArgs e)
        {
            this.Hide();
            frmDangNhap frm = new frmDangNhap();
            frm.ShowDialog();
        }

        public void TabCreating(TabControl TabControl, string Text, Form Form)
        {
            int Index = KiemTraTonTai(TabControl, Text);
            if (Index >= 0)
            {
                TabControl.SelectedTab = TabControl.TabPages[Index];
                TabControl.SelectedTab.Text = Text;
            }
            else
            {
                TabPage TabPage = new TabPage { Text = Text };
                TabControl.TabPages.Add(TabPage);
                TabControl.SelectedTab = TabPage;
                Form.TopLevel = false;
                Form.Parent = TabPage;
                Form.Show();
                Form.Dock = DockStyle.Fill;
            }
        }

        static int KiemTraTonTai(TabControl TabControlName, string TabName)
        {
            int temp = -1;
            for (int i = 0; i < TabControlName.TabPages.Count; i++)
            {
                if (TabControlName.TabPages[i].Text == TabName)
                {
                    temp = i;
                    break;
                }
            }
            return temp;
        }

    }
}